package com.wuseguang.springcloud.controller;


import com.wuseguang.springcloud.Filter.RequestParameterWrapper;
import com.wuseguang.springcloud.entity.StudentFaces;
import com.wuseguang.springcloud.service.StudentFacesService;
import com.wuseguang.springcloud.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.persistence.criteria.CriteriaBuilder;

/**
 * <p>
 * 学生人脸表 前端控制器
 * </p>
 *
 * @author 
 * @since 2020-02-26
 */
@RestController
@RequestMapping("/studentFaces")
public class StudentFacesController {


    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private StudentFacesService studentFacesServiceImpl;

    /**
     * 查询班级学生的人脸信息
     * @param request
     * @param classid
     * @return
     */
    @RequestMapping("/findClassStudentFaces")
    public Result findClassStudentFaces(RequestParameterWrapper request, @RequestParam("classId") Integer classid){
        logger.info("查询班级的学生人脸注册信息");
        return studentFacesServiceImpl.findClassStudentFaces(classid);
    }

    /**
     * 添加学生人脸信息
     * @param request
     * @param studentFaces
     * @return
     */
    @RequestMapping("/addSutdentFaces")
    public Result addSutdentFaces(RequestParameterWrapper request, @RequestBody StudentFaces studentFaces){
        logger.info("添加学生人脸注册信息");
        //获取学校id
        String schoolId = request.getParam("schoolId");
        studentFaces.setSchoolId(Integer.valueOf(schoolId));
        return studentFacesServiceImpl.addSutdentFaces(studentFaces);
    }

    /**
     * 删除学生人脸信息
     * @param request
     * @param studentId 学生id
     * @return
     */
    @RequestMapping("/delateStudentFaces")
    public Result delateStudentFaces(RequestParameterWrapper request,
                                     @RequestParam(value = "studentId" ,required = false) Integer  studentId,
                                     @RequestParam("classId") Integer classId){
        logger.info("删除学生的人脸信息");
        //获取学校id
        String schoolId = request.getParam("schoolId");
        return studentFacesServiceImpl.delateStudentFaces(studentId,classId,schoolId);
    }

    /**
     * 推送学生人脸信息
     * @param request
     * @param classId
     * @return
     */
    @RequestMapping("/stuentFacesRegister")
    public Result stuentFacesRegister(RequestParameterWrapper request,@RequestParam("classId") int[]classId){
        logger.info("推送学生人脸信息");
        return studentFacesServiceImpl.stuentFacesRegister(classId);
    }

    /**
     * 查询全校学生的人脸信息
     * @param request
     * @param classId 班级id
     * @param indexNo
     * @param rows
     * @param type 0 成功 1失败
     * @return
     */
    @RequestMapping("/findSchoolFaces")
    public Result findSchoolFaces(RequestParameterWrapper request,
                                  @RequestParam("classId") Integer classId,
                                  @RequestParam("indexNo") Integer indexNo,
                                  @RequestParam(value = "rows", required = false, defaultValue = "50") Integer rows,
                                  @RequestParam(value = "type",defaultValue = "0") Integer type){
        logger.info("查询全校学生的人脸信息");
        String schoolId = request.getParam("schoolId");
        return studentFacesServiceImpl.findSchoolFaces(schoolId,classId,indexNo,rows,type);
    }

    /**
     * 同步人脸到校牌
     * @return
     */
    @RequestMapping("/synchronizeFaces")
    public Result synchronizeFaces(RequestParameterWrapper request,@RequestParam("classId") Integer classId){
        logger.info("同步全校学生的人脸信息");
        String schoolId = request.getParam("schoolId");
        return studentFacesServiceImpl.synchronizeFaces(schoolId,classId);
    }
}

